﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using Mozlite.Common;

namespace Mozlite.Web.UI.Controllers
{
    public class HomeController : CommonBaseController
    {
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult LogsView()
        {
            ViewBag.Theme = "default";
            return GetThreadsView(Categories.GetCategoryFromCache("updatelog"));
        }
        private ActionResult GetThreadsView(Category category)
        {
            int? categoryID = null;
            if (category == null)
            {
                categoryID = null;
                ViewBag.Title = Local("ThreadsView.PageTitle");
            }
            else
            {
                categoryID = category.CategoryID;
                ViewBag.Title = category.CategoryName;
            }
            int size;
            var threads = Threads.GetThreads(new ThreadQuery { IsDesc = true, OrderBy = "ThreadID", PageSize = 20, PageIndex = PageIndex - 1, IsApproved = true, CategoryID = categoryID }, out size);
            ViewBag.Pages = (int)Math.Ceiling(size * 1.0 / 20);
            return View(threads);
        }

    }
}
